<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../../js/vue.js"></script>
    <style>
        #app {
            width: 500px;
            /* height: 300px; */
            margin: 100px auto;
        }

        .navBar {
            overflow: hidden;
            background-color: #000;
            color: darkgoldenrod;
            height: 40px;
            line-height: 40px;
            text-align: center;
        }

        .nav {
            float: left;
            width: 100px;
            height: 40px;
            cursor: context-menu;
        }

        .active {
            background-color: darkorange;
            color: #fff;
        }

    </style>
</head>

<body>
    <div id="app">
        <div class="navBar">
            <div class="nav" :class="{active:activeindex == item.id}" v-for="item in list" :key="item.id"
                @mousemove=active(item.id)>
                {{item.msg}}</div>
        </div>
    </div>
</body>
<script>
    new Vue({
        el: "#app",
        data: {
            activeindex: 1,
            list: [{id: 1, msg: "手机"}, {id: 2, msg: "电脑"}, {id: 3, msg: "衣服"}, {id: 4, msg: "鞋子"}, {id: 5, msg: "帽子"}],
        },
        methods: {
            // active(e) {
            //     var e = e || e.window;
            //     var target = e.target || e.srcElement;
            //     this.activeindex = target.id;
            //     console.log(target.item);
            // }
            active(id) {
                this.activeindex = id;
                console.log(id);
            }
        },
        watch: {

        }
    })
</script>

</html>